<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
		<meta name="viewport" id="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
		<meta name="format-detection" content="telephone=no" />
        <link rel="stylesheet" href="/static/lib/layui-v2.5.6/layui-v2.5.6/layui/css/layui.css">
		<link rel="stylesheet" href="/static/css/listMobile.css" type="text/css"/>
        <!-- <link href="./webAPP/css/my-indent.css" rel="stylesheet" type="text/css"> -->
		<title>全部订单</title>
	</head>
	<body>
		<div class="zjzz-buylist-wear">
			
			<div class="zjzz-buylist-top">
				<span class="zjzz-buylist-t2">送货上门订单</span>
				<span class="zjzz-buylist-t3">
					<span class="zjzz-buylist-t4"></span>
                </span>
			</div>
			<div class="zjzz-buylist-mid" style="margin-top: 50px;">
				<!--全部-->
				<div class="zjzz-buylist-m1">
					
				</div>
			</div>
        </div>
        
        <div id="orderDetails" style="display: none;">
            <div class="layui-form-item">
                <label class="layui-form-label">订单号</label>
                <div class="layui-input-block id_info1 info"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-block userid_info1 info"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">用户ID</label>
                <div class="layui-input-block buyerid_info1 info"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">订单时间</label>
                <div class="layui-input-block createdate_info1 info"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">订单状态</label>
                <div class="layui-input-block orderstatus_info1 info"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">付款方式</label>
                <div class="layui-input-block paymethod_info1 info"></div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                  <label class="layui-form-label">付款订单</label>
                  <div class="layui-input-inline payorderid_info1 info"></div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label">付款时间</label>
                  <div class="layui-input-inline paydate_info1 info"></div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">联系方式</label>
                <div class="layui-input-block phone_info1 info"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">送货地址</label>
                  <div class="layui-input-inline Addressid_info1 info"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">详细地址</label>
                <div class="layui-input-block Address_info1 info"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">订单总价</label>
                <div class="layui-input-block amount_info1 info"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block comment_info1 info"></div>
            </div>
    
            <table class="layui-table" lay-skin="line">
                <thead>
                    <tr>
                      <th>商品名称</th>
                      <th>商品规格</th>
                      <th>商品单价</th>
                      <th>商品数量</th>
                    </tr> 
                </thead>
                <tbody id="commodities_info1"></tbody>
            </table>
    
        </div>


		<script src="/static/lib/jquery-1.9.1.min.js"></script>
        <script src="/static/lib/layui-v2.5.6/layui-v2.5.6/layui/layui.js"></script>
		<script>
		    var tag = '',machineId,order,status1,createdateStart,createdateEnd,paydateStart,paydateEnd
            var pageNum = 1
            layui.use(['table','laydate','form','util'], function(){
            var $ = layui.jquery;
            var table = layui.table;
            var laydate =layui.laydate;
            var form = layui.form
            var util = layui.util;
            orderList(1)
            $(window).unbind("scroll").bind("scroll", function(){
                var scrollTop = $(this).scrollTop(),scrollHeight = $(document).height(),windowHeight = $(this).height();
                var positionValue = (scrollTop + windowHeight) - scrollHeight;
                if (positionValue >= -1) {
                    if (pagenum != 10000) {
                        orderList(pageNum)
                    }
                }
            });
        // 查询栏的显示与隐藏
            $(document).on("click",".accept_btn",function() {
                var OrderID = $(this).siblings(".order_btn").attr("id")
                var machine_id = $(this).siblings(".order_btn").attr("place")
                layer.open({
                    content: '订单已送达？',
                    btn: ['确定', '取消'],
                    yes: function(index){
                        $.ajax({
                            type: 'post',
                            url: "/supplier/bookOrderAdmin/determineFinishDoorToDoorOrder",
                            data: {bookOrderID: OrderID,machineID: machine_id},
                            dataType: "json",
                            success: function(mag){
                                layer.msg(mag.message)
                                layer.close(index);
                            },
                            error: function(){
                                layer.msg('参数或服务器错误')
                            }
                        })
                    }
                });
            })
            $(document).on("click",".order_btn",function() {
                var orderid = $(this).attr("id")
                var machine_id = $(this).attr("place")
                $.ajax({
                    type: "post",
                            //TODO:
                    url: "/supplier/bookOrderAdmin/getOrderDetail",
                    data: {order_id: orderid},
                    dataType: "json",
                    async: false,
                    success: function(mag){
                        $(".id_info1").html('<span style="color: #f173e1;">'+mag.data.id+'</span>')
                        $(".userid_info1").html(mag.data.user.nickname)
                        $(".buyerid_info1").html(status(mag.data.user.id))
                        $(".createdate_info1").html(ctime(mag.data.create_date))
                        $(".orderstatus_info1").html(isStatus(mag.data.order_status))
                        $(".machineid_info1").html(mag.data.machine_id)
                        $(".containernumber_info1").html(status(mag.data.container_number))
                        $(".amount_info1").html('<span style="color: #f173e1;">'+mag.data.amount+'</span>')
                        $(".comment_info1").html(mag.data.comment)
                        $(".phone_info1").html(mag.data.user.phone)
                        $(".paymethod_info1").html(paymethodfun(mag.data.pay_method))
                        $(".payorderid_info1").html(status(mag.data.pay_order_id))
                        $(".paydate_info1").html(ctime(mag.data.pay_date))
                        if (mag.data.machine_id == 1) {
                            $(".Addressid_info1").html(mag.data.machine.place)
                            $(".Address_info1").html(mag.data.user.deliveryAddress.address)
                        } else {
                            $(".Addressid_info1").html(mag.data.machine.place)
                            $(".Address_info1").html(mag.data.machine.place_address)
                        }
                        var commodities = mag.data.commodities
                        if (commodities.length != 0) {
                            var flag = ''
                            for (var i = 0; i < commodities.length; i++) {
                                var flag1 = '<tr><td>'+ commodities[i].commodityName +'</td><td>'+ commodities[i].specifications +'</td><td>'+ commodities[i].price +'</td><td>'+ commodities[i].count +'</td></tr>' 
                                flag += flag1 
                            }
                            $("#commodities_info1").html(flag)
                        }
                            
                    }
                })
                layer.open({
                    type: 1,
                    area: ['92%', '90%'], //宽高
                    title: '送货上门订单',
                    btn: ['确认','关闭'],
                    content: $('#orderDetails').html(),
                    yes: function(index){
                        $.ajax({
                            type: "post",
                            //TODO:
                            url: "/supplier/bookOrderAdmin/determineFinishDoorToDoorOrder",
                            data: {bookOrderID: orderid,machineID: machine_id},
                            dataType: "json",
                            success: function(mag){
                                if (mag.success == true) {
                                    layer.msg(mag.message)
                                    layer.close(index);
                                }else{
                                    layer.msg(mag.message)
                                }
                            },
                            error: function(){
                                layer.msg('参数或服务器错误')
                            }
                        })
                    }
                });
            })
        })
        function orderList(pagenum) {
            $.ajax({
                type: "get",
                        //TODO:
                url: "/supplier/bookOrderAdmin/getDoorOrderList",
                data: {
                    pageNum: pagenum,
                },
                dataType: "json",
                async:false,
                success: function(res){
                    var data = res.data.list
                    for (let i = 0; i < data.length; i++) {
                        if (data[i].order_status == 1) {
                            var tag1 = '<div class="zjzz-buylist-goods1" oid="'+ data[i].id +'"><div class="zjzz-buylist-gtime"><span class="zjzz-buylist-gtime1">'+ timestampToTime(data[i].create_date) +'</span><span class="zjzz-buylist-gtime2">'+ isStatus(data[i].order_status) +'</span></div><div class="zjzz-buylist-gdetail"><span class="zjzz-buylist-gtit1 cart-title">订单编号：'+ data[i].id +'</span></div><span class="zjzz-buylist-goodsm_c"><i>应付总额：<i class="zjzz-buylist-gm4">'+ data[i].amount +'</i></i><i class="zjzz-buylist-btn_c"><a href="javascript:void(0);" id="'+ data[i].id +'" amount="'+ data[i].amount +'" place="'+ data[i].machine.id +'" class="zjzz-buylist-btn3 order_btn" style="margin:0 5px; background-Color:#F6F6F6;color:#FF9201;">订单详细</a><a href="javascript:void(0);" class="zjzz-buylist-btn3 accept_btn">确认送达</a></i></span></div>'
                        }else{
                            var tag1 = '<div class="zjzz-buylist-goods1" oid="'+ data[i].id +'"><div class="zjzz-buylist-gtime"><span class="zjzz-buylist-gtime1">'+ timestampToTime(data[i].create_date) +'</span><span class="zjzz-buylist-gtime2">'+ isStatus(data[i].order_status) +'</span></div><div class="zjzz-buylist-gdetail"><span class="zjzz-buylist-gtit1 cart-title">订单编号：'+ data[i].id +'</span></div><span class="zjzz-buylist-goodsm_c"><i>应付总额：<i class="zjzz-buylist-gm4">'+ data[i].amount +'</i></i><i class="zjzz-buylist-btn_c"><a href="javascript:void(0);" id="'+ data[i].id +'" amount="'+ data[i].amount +'" place="'+ data[i].machine.id +'" class="zjzz-buylist-btn3 order_btn" style="margin:0 5px; background-Color:#F6F6F6;color:#FF9201;">订单详细</a></i></span></div>'
                        }
                        tag += tag1
                    }
                    if (data.length != 10) {
                        pageNum  = 10000
                        $(".zjzz-buylist-m1").html(tag + '<div style="text-align: center;color: #ccc;">已加载全部订单</div>')
                    }else{
                        pageNum ++
                        console.log(pageNum)
                        $(".zjzz-buylist-m1").html(tag)
                    }
                    
                }
            })
        }
		//时间的转换封装
		function timestampToTime(timestamp) {
	        var date = new Date(timestamp * 1);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
	        Y = date.getFullYear() + '-';
	        M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
	        D = (date.getDate() < 10 ? '0'+date.getDate() : date.getDate()) + ' ';
	        h = (date.getHours() < 10 ? '0' +date.getHours() : date.getHours()) + ':';
	        m = (date.getMinutes() < 10 ? '0' +date.getMinutes() : date.getMinutes()) + ':';
	        s = (date.getSeconds() < 10 ? '0' +date.getSeconds() : date.getSeconds());
	        return Y+M+D+h+m+s;
	    }
		function isStatus(num) {
			if (num == 0) {
				return '待付款'
			}else if (num == 1) {
				return '待配送'
			}else{
				return '已送达'
			}
		}
        function dateTime(date) {
            if (date != '') {
                var dateTime = new Date(date).getTime()
            }else{
                var dateTime = ''
            }
            return dateTime
        }
        function ctime(num) {
            if (num == null) {
                var ctime = '订单未完成'
            }else {
                var ctime = layui.util.toDateString(Number(num), "yyyy.MM.dd HH:mm:ss")
            }
            return ctime
        }
        function status(num) {
            if(num == null) {
                var status = '订单未完成'
            }else {
                var status = num
            }
            return status
        }
        function paymethodfun(num) {
            if (num == '0') {
                var paymethod = '支付宝'
            }else if (num == '1'){
                var paymethod = '微信'
            }else if (num == '2'){
                var paymethod = '账户余额'
            }else {
                var paymethod = '其他支付方式'
            }
            return paymethod
        }
		</script>
	</body>
</html>
